package com.zmn.plat.services.impl.orderconfig.returnvisitcontent;

import java.util.List;
import java.util.Objects;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.dto.StatusDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.orderconfig.returnvisitcontent.ReturnVisitAnswer;
import com.zmn.plat.model.entity.orderconfig.returnvisitcontent.ReturnVisitAnswerQuery;
import com.zmn.plat.persistence.interfaces.orderconfig.returnvisitcontent.ReturnVisitAnswerDao;
import com.zmn.plat.services.interfaces.orderconfig.returnvisitcontent.ReturnVisitAnswerService;

import lombok.extern.slf4j.Slf4j;

/**
 * 描述: 回访答案配置基础接口实现类
 *
 * @author tanghongjun
 * @since 2020-04-14 11:27:25
 **/
@Slf4j
@Service
public class ReturnVisitAnswerServiceImpl implements ReturnVisitAnswerService {

    private static final String TAG = "回访答案配置基础服务接口";

    @Resource
    private ReturnVisitAnswerDao returnVisitAnswerDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param answerId
     *            id
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public ReturnVisitAnswer findById(Integer answerId) {

        if (Objects.isNull(answerId)) {
            log.error("[{}],根据id查询数据answerId为null", TAG);
            return null;
        }
        return returnVisitAnswerDao.findById(answerId);
    }

    @Override
    public Integer findMaxSort() {
        return returnVisitAnswerDao.findMaxSort();
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query
     *            查询对象
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public List<ReturnVisitAnswer> listPageByQuery(ReturnVisitAnswerQuery query) {
        int count = returnVisitAnswerDao.countByQuery(query);
        query.setTotalCount(count);
        return returnVisitAnswerDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query
     *            查询对象
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public List<ReturnVisitAnswer> listByQuery(ReturnVisitAnswerQuery query) {
        return returnVisitAnswerDao.listByQuery(query);
    }

    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param returnVisitAnswer
     *            待修改数据
     * @return java.lang.Integer
     * @author tanghongjun
     * @since 2019/11/12
     **/
    @Override
    public Integer updateReturnVisitAnswerByKey(ReturnVisitAnswer returnVisitAnswer) {

        if (Objects.isNull(returnVisitAnswer.getAnswerId())) {
            log.error("[{}],根据id修改数据,ReturnVisitAnswer为null", TAG);
            return null;
        }
        return returnVisitAnswerDao.updateReturnVisitAnswerByKey(returnVisitAnswer);
    }

    @Override
    public int updateStatusBatch(List<Integer> arrayIds, int status, String updater) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(arrayIds);
        dto.setStatus(status);
        dto.setUpdater(updater);
        dto.setUpdateTime(DateUtil.getNow());
        return returnVisitAnswerDao.updateStatusBatch(dto);
    }

    @Override
    public Integer updateSortKey(int id, int sort, String updater) {
        ReturnVisitAnswer returnVisitCategory = new ReturnVisitAnswer();
        returnVisitCategory.setAnswerId(id);
        returnVisitCategory.setSort(sort);
        returnVisitCategory.setUpdater(updater);
        returnVisitCategory.setUpdateTime(DateUtil.getNow());
        return returnVisitAnswerDao.updateSortKey(returnVisitCategory);
    }

    @Override
    public Integer updateFirstLetterByKey(int id, String firstLetter, String updater) {
        ReturnVisitAnswer returnVisitContent = new ReturnVisitAnswer();
        returnVisitContent.setAnswerId(id);
        returnVisitContent.setFirstLetter(firstLetter);
        returnVisitContent.setUpdater(updater);
        returnVisitContent.setUpdateTime(DateUtil.getNow());
        return returnVisitAnswerDao.updateFirstLetterByKey(returnVisitContent);
    }

    /**
     * 描述: 新增数据
     *
     * @param returnVisitAnswer
     *            待新增数据
     * @return java.lang.Integer 主键key
     * @author tanghongjun
     * @since 2019/11/12
     **/
    @Override
    public Integer insert(ReturnVisitAnswer returnVisitAnswer) {
        return returnVisitAnswerDao.insert(returnVisitAnswer);
    }

}